//
//  ShopTableViewCell.m
//  jianpai
//
//  Created by yrapp on 15/12/31.
//  Copyright © 2015年 yrapp. All rights reserved.
//

#import "ShopTableViewCell.h"

@implementation ShopTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
 
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        self.contentView.backgroundColor = [UIColor colorWithRed:236.0/255 green:240.0/255 blue:242.0/255 alpha:1];
    
        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 5, kWidth, 112)];
        backView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:backView];
        
        
        
        
        
        _selectButtton = [[UIButton alloc] initWithFrame:CGRectMake(0, (120 - 90) / 2, 45, 90)];
        [_selectButtton setImage:[UIImage imageNamed:@"check_box@2x"] forState:(UIControlStateNormal)];
        _selectButtton.imageEdgeInsets = UIEdgeInsetsMake((90 - 20) / 2, 12.5, (90 - 20) / 2, 12.5);
        //_selectButtton.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_selectButtton];
        
        
        _shopImageView = [[UIImageView alloc] initWithFrame:CGRectMake(45, 15, 80, 90)];
        _shopImageView.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_shopImageView];
        
        
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_shopImageView.frame.origin.x + 10 + _shopImageView.frame.size.width, 10, kWidth - 20 - _shopImageView.frame.origin.x - _shopImageView.frame.size.width, 30)];
        _titleLabel.font = [UIFont systemFontOfSize:11];
       // _titleLabel.text = @"欧普照明四灯取暖浴霸正品 超薄换气三合一多功能卫生间传统吊顶";
        _titleLabel.numberOfLines = 0;
        //_titleLabel.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_titleLabel];

        _detailsLabel = [[UILabel alloc] initWithFrame:CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 5,_titleLabel.frame.size.width,30)];
       // _detailsLabel.backgroundColor = [UIColor grayColor];
        
        _detailsLabel.text = @"颜色分类:[普通吊顶] 流金岁月 取暖+照明+换气三合一/开孔30x30cm";
        _detailsLabel.numberOfLines = 0;
        _detailsLabel.font = [UIFont systemFontOfSize:11];
        _detailsLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_detailsLabel];

        _addButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _addButton.frame = CGRectMake(kWidth - 40, _detailsLabel.frame.origin.y + _detailsLabel.frame.size.height + 5 - 20, 40, 60);
        [_addButton setImage:[UIImage imageNamed:@"加"] forState:(UIControlStateNormal)];
        _addButton.imageEdgeInsets = UIEdgeInsetsMake(20, 0, 20, 20);
//        _addButton.layer.borderColor = [UIColor grayColor].CGColor;
//        _addButton.layer.borderWidth = 1;
        [self.contentView addSubview:_addButton];
        
        
        _numField = [[UITextField alloc] initWithFrame:CGRectMake(_addButton.frame.origin.x - 29, _addButton.frame.origin.y + 20, 30, 20)];
        _numField.layer.borderColor = [UIColor colorWithRed:177.0/255 green:177.0/255 blue:177.0/255 alpha:1].CGColor;
        _numField.layer.borderWidth = 1;
        _numField.text = @"1";
        _numField.textAlignment = NSTextAlignmentCenter;
        _numField.keyboardType = UIKeyboardTypeNumberPad;

        _numField.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_numField];
        
        _deleButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _deleButton.frame = CGRectMake(_numField.frame.origin.x - 41 , _numField.frame.origin.y - 20, 22 + 20, 60);
//        _deleButton.layer.borderWidth = 1;
//        _deleButton.layer.borderColor = [UIColor grayColor].CGColor;
        [_deleButton setImage:[UIImage imageNamed:@"减"] forState:(UIControlStateNormal)];
        _deleButton.imageEdgeInsets = UIEdgeInsetsMake(20, 20, 20, 0);
        [self.contentView addSubview:_deleButton];
        
        _nowPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(_titleLabel.frame.origin.x,_detailsLabel.frame.origin.y + _detailsLabel.frame.size.height + 7.5, 40, 20)];
        _nowPriceLabel.textColor = [UIColor redColor];
        _nowPriceLabel.font = [UIFont systemFontOfSize:12];
        _nowPriceLabel.text = @"¥ 199";
        [self.contentView addSubview:_nowPriceLabel];

//        _oldPricelabel = [[UILabel alloc] initWithFrame:CGRectMake(_nowPriceLabel.frame.origin.x + _nowPriceLabel.frame.size.width + 10, _nowPriceLabel.frame.origin.y, 40, 20)];
//        _oldPricelabel.textColor = [UIColor grayColor];
//        _oldPricelabel.font = [UIFont systemFontOfSize:12];
//        _oldPricelabel.text = @"¥899";
//        [self.contentView addSubview:_oldPricelabel];
//        
//        UIView *deleLine = [[UIView alloc] initWithFrame:CGRectMake(_oldPricelabel.frame.origin.x, _oldPricelabel.frame.origin.y + 10, _oldPricelabel.frame.size.width, 1)];
//        deleLine.backgroundColor = [UIColor grayColor];
//        [self.contentView addSubview:deleLine];
        
//        //要自适应宽度
//        _numbLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth - 60, _oldPricelabel.frame.origin.y, 40, 20)];
//        _numbLabel.font = [UIFont systemFontOfSize:12];
//        _numbLabel.textAlignment = NSTextAlignmentRight;
//        _numbLabel.text = @"x 1";
//        [self.contentView addSubview:_numbLabel];
        
    }
    
    return self;
    
}


- (void)setModel:(ShopModel *)model {
    
    self.titleLabel.text = model.title;
    self.nowPriceLabel.text = [NSString stringWithFormat:@"¥%@",model.price];
    [self.nowPriceLabel sizeToFit];
    [self.shopImageView sd_setImageWithURL:[NSURL URLWithString:model.pic_s] placeholderImage:nil];
    //self.detailsLabel.text = ;
    
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
